{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Largest Product of 3 Elements\n",
    "\n",
    "[The Original Question](https://mp.weixin.qq.com/s/bn7PVVCn-AUjt-sCl6pQ8g)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Question\n",
    "\n",
    "You are given an array of integers. Return the largest product that can be made by multiplying any 3 integers in the array."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example\n",
    "\n",
    "`[-4, -4, 2, 8]` should return `128` as the largest product can be made by multiplying $(-4)\\times(-4)\\times 8 = 128$."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "def maximum_product_of_three(lst):\n",
    "    # Fill this in.\n",
    "    lst.sort()\n",
    "    max_production = lst[-1] * lst[-2] * lst[-3]\n",
    "    min_production = lst[-1] * lst[0] * lst[1]\n",
    "    if max_production > min_production:\n",
    "        return max_production\n",
    "    else:\n",
    "        return min_production\n",
    "    pass"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "128\n"
     ]
    }
   ],
   "source": [
    "print(maximum_product_of_three([-4, -4, 2, 8]))\n",
    "# 128"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
